<template>
  <div id="pdf" style="margin: 5px">
    <table>
      <colgroup>
        <col width="110">
        <col width="120">
        <col width="110">
        <col width="150">
        <col width="150">
        <col width="100">
        <col width="150">
      </colgroup>
      <thead>
      <tr>
        <th>姓名</th>
        <th>{{ this.information.name }}</th>
        <th>性别</th>
        <th>{{ this.information.sex }}</th>
        <th>民族</th>
        <th>{{ this.information.thnic }}</th>
        <th rowspan="5" style="padding: 0">
          <img width="137px" height="180px" src="https://img.zcool.cn/community/032727c5959bc4da8012193a3bf55cb.jpg"/>
        </th>
      </tr>
      <tr>
        <th>曾用名</th>
        <td>{{ this.information.formerName }}</td>
        <th>出生日期</th>
        <td>{{ this.information.birthdate }}</td>
        <th>政治面貌</th>
        <td>{{ this.information.polstatus }}</td>
      </tr>
      <tr>
        <th>班级</th>
        <td>{{ this.information.classNo }}</td>
        <th>学号</th>
        <td>{{ this.information.accountNo }}</td>

        <th>年级</th>
        <td>{{ this.information.gradeName }}</td>
      </tr>
      <tr>
        <th>学院</th>
        <td>{{ this.information.departmentName }}</td>
        <th>专业名称</th>
        <td>{{ this.information.majorName }}</td>
        <th>班级简称</th>
        <td>{{ this.information.classShortName }}</td>
      </tr>
      <tr>
        <th>学制</th>
        <td>{{ this.information.educationalSystem }}</td>
        <th>手机号码</th>
        <td>{{ this.information.contact }}</td>
        <th>入学日期</th>
        <td>{{ this.information.enrollmentDate }}</td>
      </tr>
      <tr>
        <th>证件号</th>
        <td colspan="2">{{ this.information.idnumber }}</td>
        <th>家庭地址</th>
        <td colspan="2">{{ this.information.addressOfHousehold }}</td>
        <td rowspan="5">
          <img width="137px" height="180px" src="https://img.zcool.cn/community/032727c5959bc4da8012193a3bf55cb.jpg"/>
        </td>
      </tr>
      <tr>
        <th>QQ号码</th>
        <td>{{ this.information.qq }}</td>
        <th>电子邮箱</th>
        <td>{{ this.information.email }}</td>
        <th>邮政编码</th>
        <td>{{ this.information.postalCode }}</td>
      </tr>
      <tr>
        <th>寝室号</th>
        <td>{{ this.information.dormitoryNumber }}</td>
        <th>籍贯</th>
        <td>{{ this.information.nativePlace }}</td>
        <th>辅导员</th>
        <td>{{ this.information.instructorName }}</td>
      </tr>
      <tr>
        <th>入学方式</th>
        <td>{{ this.information.admissionMethod }}</td>
        <th>毕业中学</th>
        <td>{{ this.information.middleSchool }}</td>
        <th>外语类别</th>
        <td>{{ this.information.foreignLanguage }}</td>
      </tr>
      <tr>
        <th>身高</th>
        <td>{{ this.information.height }}</td>
        <th>体重</th>
        <td>{{ this.information.weight }}</td>
        <th>备注</th>
        <td>{{ this.information.notes }}</td>
      </tr>
      <tr>
        <th>监护人1姓名</th>
        <td>{{ this.information.guardian1 }}</td>
        <th>监护人1籍贯</th>
        <td></td>
        <th>监护人1证件号码</th>
        <td colspan="2">{{ this.information.guardian1Id }}</td>
      </tr>
      <tr>
        <th>监护人2姓名</th>
        <td>{{ this.information.guardian2 }}</td>
        <th>监护人2籍贯</th>
        <td></td>
        <th>监护人2证件号码</th>
        <td colspan="2">{{ this.information.guardian2Id }}</td>

      </tr>
      </thead>
    </table>
    <table
        style="border-collapse:collapse ; margin-top:-1px ; width: 818px  ">
      <tbody>
      <tr>
        <th colspan="7">奖项竞赛</th>
      </tr>
      <tr>
        <th>姓名</th>
        <th colspan="2">比赛名称</th>
        <th>比赛时间</th>
        <th>竞赛级别</th>
        <th>奖项</th>
        <th>指导教师</th>
      </tr>
      <tr v-for="(award, index) in this.awardInformation" :key="index">
        <td>{{ this.information.name }}</td>
        <td colspan="2">{{ this.awardInformation[index].awardName || "null" }}</td>
        <td>{{ awardInformation[index].awardData || "null" }}</td>
        <td>{{ awardInformation[index].competitionTypeName || "null" }}</td>
        <td>{{ awardInformation[index].awardLevel || "null" }}</td>
        <td>{{ awardInformation[index].teacher || '无' }}</td>
      </tr>
      </tbody>
    </table>

    <table
        style="border-collapse:collapse ; margin-top:-1px ; width: 818px  ">
      <tbody>
      <tr>
        <th colspan="10">综测情况</th>
      </tr>
      <tr>
        <th width="81.72px">综测年度</th>
        <th width="80px">思想品德（A1）</th>
        <th width="80px">学业成绩（A2）</th>
        <th width="80px">身心素质（A3）</th>
        <th width="100px">社会工作与对外交流（B1）</th>
        <th width="100px">公益服务与社会实践（B2）</th>
        <th width="80px">文体艺活动（B3）</th>
        <th width="82px">学术与创新创业（B4）</th>
        <th width="75px">总分</th>
        <th width="75px">排名</th>
      </tr>
      <tr v-for="(award, index) in this.complexInformation" :key="index">
        <td>{{ this.complexInformation[index].year }}</td>
        <td>{{ this.complexInformation[index].scoreA1 }}</td>
        <td>{{ this.complexInformation[index].scoreA2 }}</td>
        <td>{{ this.complexInformation[index].scoreA3 }}</td>
        <td>{{ this.complexInformation[index].scoreB1 }}</td>
        <td>{{ this.complexInformation[index].scoreB2 }}</td>
        <td>{{ this.complexInformation[index].scoreB3 }}</td>
        <td>{{ this.complexInformation[index].scoreB4 }}</td>
        <td>{{ this.complexInformation[index].scoreAll }}</td>
        <td>{{ this.complexInformation[index].ranking }}</td>
      </tr>
      </tbody>
    </table>

    <table
        style="border-collapse:collapse ; margin-top:-1px ; width: 818px">
      <tbody>
      <tr>
        <th colspan="7">任职情况</th>
      </tr>
      <tr>
        <th>姓名</th>
        <th>学号/工号</th>
        <th>组织名称</th>
        <th>职位名称</th>
        <th>任职时间</th>
        <th>主要职责</th>
        <th>备注</th>

      </tr>
      <tr v-for="(award, index) in this.unitInformation" :key="index">
        <td>{{ this.information.name }}</td>
        <td>{{ this.information.accountNo }}</td>
        <td>{{ this.unitInformation[index].unitName }}</td>
        <td>{{ this.unitInformation[index].unitPosition }}</td>
        <td>{{ this.unitInformation[index].unitDate }}</td>
        <td>{{ this.unitInformation[index].unitDuty }}</td>
        <td>{{ this.unitInformation[index].remark }}</td>
      </tr>
      </tbody>
    </table>


    <table
        style="border-collapse:collapse ; margin-top:-1px ; width: 818px">
      <tbody>
      <tr>
        <th colspan="7">实习经历</th>
      </tr>
      <tr>
        <th>姓名</th>
        <th>学号/工号</th>
        <th>单位名称</th>
        <th>职位名称</th>
        <th>任职时间</th>
        <th>主要职责</th>
        <th>备注</th>

      </tr>
      <tr v-for="(award, index) in this.fieldWorkInformation" :key="index">
        <td>{{ this.information.name }}</td>
        <td>{{ this.information.accountNo }}</td>
        <td>{{ this.fieldWorkInformation[index].unitName }}</td>
        <td>{{ this.fieldWorkInformation[index].unitPosition }}</td>
        <td>{{ this.fieldWorkInformation[index].unitDate }}</td>
        <td>{{ this.fieldWorkInformation[index].unitDuty }}</td>
        <td>{{ this.fieldWorkInformation[index].remark }}</td>
      </tr>
      </tbody>
    </table>


    <table
        style="border-collapse:collapse ; margin-top:-1px ; width: 818px">
      <tbody>
      <tr>
        <th colspan="7">项目经历</th>
      </tr>
      <tr>
        <th>姓名</th>
        <th>学号/工号</th>
        <th>项目名称</th>
        <th>参与时间</th>
        <th>主要职责</th>
        <th>项目负责人</th>
        <th>备注</th>

      </tr>
      <tr v-for="(award, index) in this.projectInformation" :key="index">
        <td>{{ this.information.name }}</td>
        <td>{{ this.information.accountNo }}</td>
        <td>{{ this.projectInformation[index].projectName }}</td>
        <td>{{ this.projectInformation[index].projectDate }}</td>
        <td>{{ this.projectInformation[index].projectDuty }}</td>
        <td>{{ this.projectInformation[index].projectManage }}</td>
        <td>{{ this.projectInformation[index].remark }}</td>
      </tr>
      </tbody>
    </table>
  </div>
  <div style="text-align: center ; margin-top: 10px">
    <el-button type="primary" round
               :icon="download"
               @click="exportPic('pdf')">导出
    </el-button>
  </div>


</template>

<script>
import request from "@/util/request.js";
import html2Canvas from 'html2canvas';
import download from "@element-plus/icons/lib/Download.js";

export default {
  computed: {
    download() {
      return download
    }
  },
  data() {
    return {
      information: {},
      awardInformation: [],
      complexInformation: [],
      fieldWorkInformation: [],//实习经历信息
      projectInformation: [], //项目经历
      unitInformation: [], // 部门任职信息
    }
  },

  created() {
    window.parent.getTemplateData((data) => {
      this.information = data;
    })
    this.detailedInformation1(this.information.accountNo)
  },
  methods: {
    //学生所有信息
    detailedInformation1(scope) {
      this.getAward(scope)
      this.getRelatedFieldWork(scope)
      this.getRelatedProject(scope)
      this.getUnitInformation(scope)
      this.getComplexInformation(scope)
      this.detailedInformation = true
    },
// 获取竞赛荣誉信息
    getAward(scope) {
      request.get("/info_award/getListByAccountNo?accountNo=" + scope).then(res => {
        this.awardInformation.push(...res.data.data)
      })
    },
    // 获取综测信息
    getComplexInformation(scope) {
      request.get("/info_complex/" + scope).then(res => {
        console.log("综测")
        this.complexInformation.push(...res.data.data)
      })
    },
    // 获取部门任职信息
    getUnitInformation(scope) {
      request.get("/related_unit/" + scope).then(res => {

        this.unitInformation.push(...res.data.data)

      })
    },
    // 获取实习经历
    getRelatedFieldWork(scope) {
      request.get("/related_fieldwork/" + scope).then(res => {
        this.fieldWorkInformation.push(...res.data.data)
      })
    },
    // 获取项目经验
    getRelatedProject(scope) {
      request.get("/related_project/" + scope).then(res => {
        this.projectInformation.push(...res.data.data)
      })
    },
    //导出图片
    exportPic(DivID) {
      html2Canvas(document.querySelector("#" + DivID)).then(canvas => {
        let dataURL = canvas.toDataURL("image/png");
        if (dataURL !== "") {
          var a = document.createElement('a');
          // 修正下载文件名的代码
          a.download = `${this.information.name}${this.information.accountNo}.png`;
          a.href = dataURL;
          a.click();
        }
      });
    }
  }
}


</script>

<style scoped>
table {
  border-collapse: collapse;
  text-align: center;
  vertical-align: middle;
  font-family: "宋体", SimSun;
}

th, td {
  border: 1px solid black;
  padding: 10px 0;
  font-family: "Times New Roman", Times, serif;
}

</style>
